import java.util.*;

public class Listework {
	
	private final int MAX = 500;
	private int liste[] = new int[MAX];
	private int ptr;
	private int anzahlLinerar = 0;
	private int anzahlBinaer = 0;
	
	public Listework ()
	{
		ptr = 0;
	}
	
	public void show()
	{
		for(int i=0; i < ptr; i++)
		{
			System.out.print(liste[i] + " ");
			if (i%20 == 0)
				System.out.println("");
			
		}
		System.out.println("");
	}
	
	public void sort()
	{
		int right = ptr;
		int h;
		
		while (right >1)
		{
			for (int i = 0 ; i < right-1; i++)
			{
				if (liste[i] > liste[i+1])
				{
					// tausche 
					h = liste[i];
					liste[i] = liste[i+1];
					liste[i+1]=h;
				}
			}
			right--;
		}
	}
	
	public void insertElement(int anz)
	{
		int value;
		if (anz >= MAX)
			ptr = MAX;
		else
			ptr = anz;
			
		for (int i=0; i < anz; i++)
		{
			value = new Random().nextInt(1000);
			liste[i]= value;
		}
	}
	
	public int searchlinear(int w)
	{
		int zahl = -1;
		for(int i = 0; i < this.MAX; i++) {
			anzahlLinerar++;
			if(this.liste[i] == w)
				zahl = i;
		}
		return zahl;
	}
	
	public int searchbinaer(int w)
	{
		int start = 0;
		int ende = this.MAX;
		int mitte;
		int zahl = -1;
		boolean gefunden = false;
		
		while(!gefunden && (start <= ende)) {
			anzahlBinaer++;
			mitte = (ende + start)/2;
			if(this.liste[mitte] == w) {
				zahl = mitte;
				gefunden = true;
			}
			else 
			{
				if(w > this.liste[mitte])
				{
					start = mitte + 1;
				}
				else
				{
					ende = mitte - 1;
				}
			}
		}
		return zahl;
	}
	
	public int searchStr(char s[], char search[]) {
		int zahl = -1;
		for(int i = 0; i < s.length; i++) {
			if(s[i] == search[0]) {
				boolean test = true;
				for(int z = 1; z < search.length; z++) {
					try {
						if(s[i + z] != search[z]) {
							test = false;
						}
					} catch(IndexOutOfBoundsException e) {
						test = false;
					}
				}
				if(test) {
					return i;
				}
			}
		}
		return zahl;
	}

	/**
	 * @return the anzahlLinerar
	 */
	public int getAnzahlLinerar() {
		return anzahlLinerar;
	}

	/**
	 * @return the anzahlBinär
	 */
	public int getAnzahlBinaer() {
		return anzahlBinaer;
	}
}


